package com.lzy.wzy.utils;

import org.apache.commons.lang.StringUtils;

import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.regex.Pattern;

public class PatternUtils {

    public static boolean checkDigitId(String id) {
        return !Pattern.matches("\\d+", id);
    }

    public static boolean checkLeaveOneTemplateAlias(String templateAlias) {
        return StringUtils.isNotBlank(templateAlias) && Pattern.matches("([a-z]+)(_)([a-z]+)(_)([a-z]+)", templateAlias) && templateAlias.endsWith("_table");
    }


    public static boolean verifyProductCode(String code){
        return Pattern.matches("([0-9]{3}.(0-9){2}.(0-9){4})",code);
    }

    public static boolean verifyCodePrefix(String code){
        return Pattern.matches("([0-9]{3}.)",code.replace("%",""));
    }

    public static boolean verifySoftVersion(String softVersion) {
        return StringUtils.isNotBlank(softVersion) && Pattern.matches("[A-Za-z.\\-_0-9]{3,50}", softVersion);
    }

    public static boolean verifyFoxEmail(String email){
        return !Pattern.matches("(\\w+)([.]\\w+)@timevary.com", email);
    }

    public static boolean checkTemplateName(String templateName) {
        return !StringUtils.isNotBlank(templateName) || !Pattern.matches("([a-zA-Z0-9.\\-_()\\u4E00-\\u9FA5]+)", templateName);
    }

    public static boolean checkFieldName(String fieldName) {
        return !Pattern.matches("([a-zA-Z0-9]+)", fieldName);
    }

    public static boolean checkProjectNumber(String projectNumber){
        return !Pattern.matches("([a-zA-Z0-9]+)", projectNumber);
    }

    public static boolean checkWorkOrderNumber(String workOrderNumber) {
        return Pattern.matches("([PBFpbf][\\d]+)", workOrderNumber);
    }

    public static boolean checkHistoricalTime(String historicalTime) {
        boolean blank = true;
        try {
            DateTimeFormatter.ofPattern("yyyy-MM-dd").parse(historicalTime);
        } catch (DateTimeParseException e) {
            blank = false;
        }
        return blank;
    }

    public static boolean checkId(String id) {
        return Pattern.matches("[a-z0-9]+", id);
    }
}
